#!/usr/bin/perl

use warnings;
use strict;

for my $file (@ARGV) {
    open my $in_fh, $file or die "can't open $file: $!\n";
    my $html = do { local $/; <$in_fh> };
    close $in_fh or die "can't close $file: $!\n";

    my %tags;
    for my $tag (qw/Source Genre Difficulty/) {
        next unless $html =~
            m!<td class=prob>\s*$tag:\s*</td>\s*<td>\s*(.*?)\s*</td>!s;
        $tags{lc $tag} = $1 if defined($1) && length($1);
    }

    print "$file: ";
    while (my ($key, $value) = each %tags) {
        printf "%s [%s] ", $key, $value;
    }
    print "\n";
}
